<%@page import="com.yymmarket.forum.cache.ForumCache,com.yymmarket.forum.user.UserBean,com.yymmarket.forum.util.SessionUtil,com.yymmarket.util.StringUtil,com.yymmarket.framework.PagingBean,java.util.*,com.yymmarket.forum.chat.*,com.yymmarket.framework.WebAction"%><%@ 
page contentType="text/vnd.wap.wml;charset=utf-8"%><%
response.setHeader("Cache-Control","no-cache");
WebAction webAction = new WebAction(request,response);
int toId = webAction.getParameterInt("toId");
List<ChatBean> list = new ArrayList<ChatBean>();
PagingBean paging = null;
int count = 0;
Integer uid = SessionUtil.getSessionUserId(request);

UserBean user = ForumCache.getUser(uid);


if(toId>0) {
	UserBean toUser = ForumCache.getUser(toId);
	if(toUser==null) {
		response.sendRedirect("chat.jsp");
	}
	ChatService chatService = ChatService.getInstance();
	
	if(user==null) {
		response.sendRedirect(response.encodeURL("chat.jsp"));
		return;
	}
	count = chatService.getCountUserChats(user.getId(),toId);
	paging = new PagingBean(webAction,count,10,"p");
	list = chatService.getUserChats(user.getId(),toId,paging.getStartIndex(),paging.getCountPerPage());
}
%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card title="聊天室">
<p>
==发言==<br/><%
	if(toId==0) {
		%>所有人:<%
	} else {
		UserBean toUser = ForumCache.getUser(toId);
		%><%=StringUtil.toWml(toUser.getUserName())%>:<br/><%		
	}
%><input name="content"/><br/>
<anchor>发言<go href="<%=response.encodeURL("doChat.jsp") %>">
<postfield name="content" value="$content" /><%
if(toId>0) {
	UserBean toUser = ForumCache.getUser(toId);
%><postfield name="toId" value="<%=toId%>" /><%
	}
%></go></anchor><%if(toId>0) {
	UserBean toUser = ForumCache.getUser(toId);
%>
|<anchor>只让<%=toUser.getGenderTA() %>看见<go href="<%=response.encodeURL("doChat.jsp") %>">
<postfield name="content" value="$content" />
<postfield name="toId" value="<%=toId%>" />
<postfield name="hide" value="1" />
</go></anchor><%} %><br/><%
	if(paging!=null){
		for(ChatBean chat:list){
%><a href="<%=response.encodeURL("newChat.jsp?toId="+chat.getFromId()) %>"><%= StringUtil.toWml(chat.getFromUser())
%></a>:<a href="<%=response.encodeURL("newChat.jsp?toId="+chat.getToId()) %>"><%= StringUtil.toWml(chat.getToUser())
%></a>,<%=StringUtil.toWml(chat.getContent()) %><br/><%	
		}
	}
%><a href="<%=response.encodeURL("chat.jsp") %>">返回聊天室</a>
</p>
</card>
</wml>